﻿@using Classified.Domain.Entities
@model User
@{
    ViewBag.Title = "Edit";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<h1>
    Edit <small>User</small></h1>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<fieldset>
    @using (Html.BeginForm("ChangePassword", "User"))
    {
        <div class="clearfix">
            @Html.LabelFor(model => model.Password)
            <div class="input form-search">
                @Html.HiddenFor(model => model.Password)
                @Html.Password("newPassword")
                @Html.Hidden("userId", Model.Id)
                <input type="submit" class="btn" value="Change Password" />
            </div>
        </div>
    }
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.Password)
        <div class="clearfix">
            @Html.LabelFor(model => model.FirstName)
            <div class="input">
                @Html.EditorFor(model => model.FirstName)
                @Html.ValidationMessageFor(model => model.FirstName)
            </div>
        </div>
          
        <div class="clearfix">
            @Html.LabelFor(model => model.LastName)
            <div class="input">
                @Html.EditorFor(model => model.LastName)
                @Html.ValidationMessageFor(model => model.LastName)
            </div>
        </div>
        <div class="clearfix">
            @Html.LabelFor(model => model.UserName)
            <div class="input">
                @Html.EditorFor(model => model.UserName)
                @Html.ValidationMessageFor(model => model.UserName)
            </div>
        </div>
        <div class="clearfix">
            @Html.LabelFor(model => model.Email)
            <div class="input">
                @Html.EditorFor(model => model.Email)
                @Html.ValidationMessageFor(model => model.Email)
            </div>
        </div>
         
        <div class="clearfix">
            <label>Roles</label>
            
            <div class="input chzn-select">
                @{
                    List<Role> roles = ViewBag.RolesList;
                }
                @foreach (var role in roles)
                {
                    if (Model.Roles != null && Model.Roles.Any(x => x.RoleName == role.RoleName))
                    {
                        <text>
                            <input type="checkbox" name="role" value="@role.RoleName" checked="checked" />
                            @role.RoleName
                        </text>
                    }
                    else
                    {
                        <text>
                            <input type="checkbox" name="role" value="@role.RoleName" />
                            @role.RoleName
                        </text>
  
                    }

                }
            </div>
        </div>
        <div class="clearfix">
            @Html.LabelFor(model => model.IsActive)
            <div class="input">
                @Html.EditorFor(model => model.IsActive)
                @Html.ValidationMessageFor(model => model.IsActive)
            </div>
        </div>
        
        <div class="clearfix">
            @Html.LabelFor(model => model.DateCreated)
            <div class="input">
                @Html.DisplayTextFor(model => model.DateCreated)
            </div>
        </div>
        <div class="actions">
            <input type="submit" class="btn primary" value="Save" />
            @if (Model != null && Model.Id > 0)
            {   <text>
                @Html.ActionLink("Delete", "Delete", new { id = Model.Id }, new { @class = "btn" })
                </text>
            }
            @Html.ActionLink("Back to List", "List", null, new { @class = "btn" })
        </div>
       
    }
</fieldset>
